package platformer;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class CollisionMonitor
{
	
	private Set<Collision> collisions;
	private Set<Drawable> drawables;
	
	public CollisionMonitor(Set<Drawable> drawables)
	{
		this.drawables = drawables;
		collisions = new HashSet<Collision>();
	}
	
	public Set<Drawable> getDrawables()
	{
		return drawables;
	}

	public void setDrawables(Collection<? extends Drawable> drawables)
	{
		if (drawables != null)
			this.drawables = (new HashSet<Drawable>(drawables));
	}
	
	public Set<Drawable> addDrawables(Collection<? extends Drawable> drawables)
	{
		if (drawables != null && drawables.isEmpty() == false)
			this.drawables.addAll(drawables);
		return this.drawables;
	}

	public Set<Collision> getCollisions(List<Drawable> ignore)
	{		
		for (Drawable s : drawables)
		{
			for (Drawable ss : drawables)
			{
				if (s.intersects(ss.getBounds()) && !s.equals(ss) && !ignore.contains(s) && !ignore.contains(ss) && (drawables.contains(s) && drawables.contains(ss)))
				{
					if (collisions.contains(ss) || collisions.contains(ss))
					{
						
					}
					else
					{
						collisions.add(new Collision(s, ss));
					}
				}
			}
		}
		
		return collisions;
	}
	
}